package com.cdtu.utils;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

/**
 * @author Mika
 * @date 2025/02/21 17:34
 **/
public class HttpUtil {
    private static final RestTemplate restTemplate = new RestTemplate();
    public static <T> T get(String url, Class<T> responseType) {
        return restTemplate.getForObject(url, responseType);
    }
    public static <T, R> T post(String url, R request, Class<T> responseType) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        HttpEntity<R> requestEntity = new HttpEntity<>(request, headers);
        return restTemplate.postForObject(url, requestEntity, responseType);
    }
}
